<!DOCTYPE html>
<html>
	<head> 
		<meta charset="UTF-8" />
		<title>修改 管理员</title>
		<link rel="stylesheet" th:href="@{/moon/css/bootstrap2.css}" />
		<link rel="stylesheet" th:href="@{/menu/metisMenu.css}" />
	</head> 
	 
	<body class="bg-pm">
		
		<div class="container-fluid" style="overflow: hidden;" id="app">
		
			<center><h2 style="margin-top:10px" class="mb-5">修改管理员</h2></center>
	
			<form class="form-horizontal" method="post" action="/openpaipai/admin/updateAdmin" onsubmit="return updateAdmin()">
  				<div class="form-group">
			    	<label for="aName" class="col-sm-2 control-label">账户名</label>
			    	<div class="col-sm-5" >
			      		<input type="text" class="form-control" id="aName" name="aName"  
			      		       required onblur="checkNameExists(this.value)" maxlength=50 th:value=${adminuser.adminname}>
			    	</div>
			    	<div class="col-sm-2" ><span id="anametips" ></span></div>
			  	</div> 
			  	<div class="form-group">
			    	<label for="aPass" class="col-sm-2 control-label">新密码</label>
			    	<div class="col-sm-5" >
			      		<input type="password" class="form-control" id="aPass" name="aPass" placeholder="请输入6-12位数字、字母密码" 
			      			   required onchange="checkPassword(this.value)" maxlength=12 th:value="${adminuser.adminpass}">
			    	</div>
			    	<div class="col-sm-2" ><span id="apasstips" ></span></div>
			  	</div>
			  	<div class="form-group">
			    	<label for="aPhone" class="col-sm-2 control-label">手机号</label>
			    	<div class="col-sm-5" >
			      		<input type="text" class="form-control" id="aPhone" name="aPhone" placeholder="请输入手机号" 
			      		       required oninput="checkPhoneNumber(this.value)" th:value="${adminuser.adminphone}">
			    	</div>
			    	<div class="col-sm-2" ><span id="aphonetips" ></span></div>
			  	</div>
			  	
			  	
			  	<div class="form-group">
    				<div class="col-sm-offset-2 col-sm-10">
      					<input type="button" class="btn btn-bg btn-info" onclick="reload();" value="取消">
      					<input type="submit" class="btn btn-bg btn-info" value="提交" style="margin-left:10px">
    				</div>
  				</div>
			</form>
			
			<script th:src="@{/moon/js/jquery.js}"></script>
			<script th:src="@{/moon/js/vue.js}"></script>
			<script th:src="@{/layer/layer.js}"></script>
			<script th:src="@{/page/jqpaginator.js}"></script>
			<script th:inline="javascript">
			
			var oldname=[[${adminuser.adminname}]];
			
			//-- 利用ajax异步请求，验证用户名是否可用
			//-- 一般在进行验证前，利用一些手段如正则表达式初步验证用户名的合法性
			function checkNameExists(aName){
				$.post(
						"/auction/Admin/selectAdminByName",
						{ aName:$('#aName').val() },
						function (data) {
							if ((data == "false") || ($('#aName').val() == oldname)) { 
					    		document.getElementById("anametips").innerHTML = "用户名可用";
							}else{
								document.getElementById("anametips").innerHTML = "用户名不可用";
							}
						}
					);
			}
			
			
			//正则判断密码是否合法
			function checkPassword(aPass){
				var myreg = /^[a-zA-Z0-9]{6,12}$/;
			      if (!myreg.test(aPass)) {  
			    	  document.getElementById("apasstips").innerHTML = "密码由6-12位数字、字母自由组成";
			      } else {  
			    	  document.getElementById("apasstips").innerHTML = "密码正常";
			      } 
				
			}
			
			//正则判断手机号是否合法
			function checkPhoneNumber(aPhone){
				var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
			      if (!myreg.test(aPhone)) {  
			    	  document.getElementById("aphonetips").innerHTML = "手机号不可用";
			      } else {  
			    	  document.getElementById("aphonetips").innerHTML = "手机号可用";
			      } 
				
			}
			
			//下拉框回显
			$(function(){
				$('#jurisdiction').val([[${adminuser.jurisdiction}]]);
			});
			
			
			function reload(){
				location.href="/auction/Admin/adminiframe/selectAdminByCond";
			}
			
			//-- 不执行表单的submit的跳转，同时保留requirded的特性
			function updateAdmin(){

				$.post(
					"/auction/Admin/updateAdmin",{
						aId:[[${adminuser.adminid}]],//从model域取key值对象的属性
						aName:$('#aName').val(),
						aPass:$('#aPass').val(),
						aPhone:$('#aPhone').val(),
						Jurisdiction:[[${adminuser.jurisdiction}]]
					},
					function (data) {
						if(data=="true"){
							alert("修改成功");
							location.href="/auction/Admin/adminiframe/selectAdminByCond";
						}
						else{
							layer.alert("修改失败");
							location.href="/auction/Admin/goUpdateAdmin?aName="+oldname;	
						}
					}
				);
				
				return false;
			}

			</script>
		</div>
	</body>
</html>